/* 有序关联容器 ==》红黑树  增删查O(log2n) 2是底数(树的层数、树的高度)
 * set
 * multiset
 * map
 * multimap
 *
 * 常用增删查方法：
 * 增加：insert(val)
 * 遍历：iterator自己搜索，调用find成员方法
 * 删除：erase(key) erase(it)
 *
 * */
#include <iostream>
#include <set>
#include <map>
using namespace std;

class Stu{
private:
    int _id;
    string _name;
    friend ostream & operator<<(ostream& out,const Stu &stu);
public:
    Stu(int id=0,string name=" "):_id(id),_name(name){}
};

ostream & operator<<(ostream& out,const Stu &stu){
    out<<"id: "<<stu._id<<" name: "<<stu._name<<endl;
    return out;
}

int main(){
    map<int,Stu> stuMap;
    stuMap.insert({1,Stu(1,"wyx")});
    stuMap.insert({2,Stu(2,"wyx2")});
    stuMap.insert({3,Stu(3,"wyx3")});

    cout<<stuMap[2]<<endl;
    /*
    set<Stu> s1;
    s1.insert(Stu(1,"wyx"));
    s1.insert(Stu(2,"lxy"));

    for (auto i = s1.cbegin(); i !=s1.cend(); ++i) {
        cout<<*i<<endl;
    }
    */

    /*
    set<int> s1;
    for(int i=0;i<10;i++){
        s1.insert(rand()%10+1);
    }
    for (int v:s1) {
        cout<<v<<" ";
    }
    */

    return 0;
}